package com.gee.spring.boot.rpf.controller;


import com.gee.spring.boot.rpf.config.cache.ClientCacheConfig;
import org.springframework.web.bind.annotation.RestController;
import com.gee.spring.boot.rpf.util.result.Result;
import com.gee.spring.boot.rpf.util.result.ResultCode;
import com.gee.spring.boot.rpf.util.result.ResultUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import com.gee.spring.boot.rpf.service.RefNextClientEditorParamSourceService;
import com.gee.spring.boot.rpf.entity.RefNextClientEditorParamSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author gee
 * @since 2021-02-13
 */
@RestController
@RequestMapping("/rpf/refNextClientEditorParamSource")
public class RefNextClientEditorParamSourceController {
    private final Logger logger = LoggerFactory.getLogger(RefNextClientEditorParamSourceController.class);

    @Autowired
    public RefNextClientEditorParamSourceService refNextClientEditorParamSourceService;

    @Autowired
    private ClientCacheConfig clientCacheConfig;

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable("id") String id){
            RefNextClientEditorParamSource refNextClientEditorParamSource = refNextClientEditorParamSourceService.getById(id);
            if (refNextClientEditorParamSource == null){
                return ResultUtil.error(ResultCode.NULL_DATA);
            }
            return ResultUtil.successWithData(refNextClientEditorParamSource);
    }

    @GetMapping("/refreshCache")
    public Result refreshCache(){
        clientCacheConfig.initRefNextClientEditorParamSourceCache();
        return ResultUtil.success();
    }
}